package com.itheima.youdianda.controller;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.domain.YddArticle;
import com.itheima.youdianda.dto.PageDto;
import com.itheima.youdianda.dto.YddArticleDto;
import com.itheima.youdianda.service.YddArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/ydd_article")
@RestController
@Slf4j
public class YddArticleController {
    @Autowired
    private YddArticleService yddArticleService;

    @GetMapping("/list")
    public R<PageDto> list(Integer page, Integer limit, Integer cateid, String title, Long start_time, Long end_time) {
        PageDto<YddArticleDto> pageInfo = yddArticleService.artList(page, title, limit, cateid, start_time, end_time);
        return R.success(pageInfo);
    }

    @GetMapping("/del")
    public R<String> del(Integer id) {
        yddArticleService.del(id);
        return R.success("删除成功");
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody YddArticle yddArticle) {
        yddArticleService.add(yddArticle);
        return R.success("添加成功");
    }

    @PutMapping("/update")
    public R<String> updateArticle(@RequestBody YddArticle yddArticle){
        yddArticleService.updateArticle(yddArticle);
        return R.success("修改成功");
    }
    @GetMapping("/rowInfo")
    public R<YddArticle> yddArticleInfo(Integer id){
        YddArticle yddArticle = yddArticleService.yddArticleInfo(id);
        return R.success(yddArticle);
    }

}
